'use strict';

/**
 * @param {Egg.Application} app - egg application
 */
const ueditor = require('egg-ueditor')

module.exports = app => {
  const { router, controller, io } = app;
  /*
  * admin
  * */
  // index
  router.get('adinin', '/admin/index/index', controller.admin.index.index);
  router.all('adinlo', '/admin/index/login', controller.admin.index.login);
  router.get('adinlgt', '/admin/index/logout', controller.admin.index.logout);
  router.get('adinmp', '/admin/index/map', controller.admin.index.map);
  router.get('adinmsg', '/admin/index/message', controller.admin.index.message);
  // admin
  router.get('adadin', '/admin/admin/index', controller.admin.admin.index);
  router.all('adadif', '/admin/admin/info', controller.admin.admin.info);
  router.get('adadlg', '/admin/admin/log', controller.admin.admin.log);
  router.get('adadelg', '/admin/admin/errlog', controller.admin.admin.errlog);
  router.get('adadrl', '/admin/admin/role', controller.admin.admin.role);
  router.all('adadri', '/admin/admin/role_info', controller.admin.admin.role_info);
  router.get('adaddlg', '/admin/admin/dblog', controller.admin.admin.dblog);
  // system
  router.all('adstin', '/admin/system/index', controller.admin.system.index);
  router.all('adstmn', '/admin/system/menu', controller.admin.system.menu);
  router.all('adstctm', '/admin/system/create_menu', controller.admin.system.create_menu);
  router.all('adstcld', '/admin/system/ctl_detail', controller.admin.system.ctl_detail);
  router.get('adstmd', '/admin/system/module', controller.admin.system.module);
  // user
  router.get('adurin', '/admin/user/index', controller.admin.user.index);
  router.all('adurdt', '/admin/user/detail', controller.admin.user.detail);
  router.all('adurad', '/admin/user/add', controller.admin.user.add);
  router.all('adurus', '/admin/user/user', controller.admin.user.user);
  // article
  router.get('adalin', '/admin/article/index', controller.admin.article.index);
  router.all('adalad', '/admin/article/add', controller.admin.article.add);
  // tools
  router.all('adtlin', '/admin/tools/index', controller.admin.tools.index);
  router.all('adtlrt', '/admin/tools/restore', controller.admin.tools.restore);
  router.post('adtlop', '/admin/tools/operate', controller.admin.tools.operate);
  router.get('adtlqr', '/admin/tools/qrcode', controller.admin.tools.qrcode);
  router.all('adtlqrt', '/admin/tools/qrcode_text', controller.admin.tools.qrcode_text);
  // common
  router.post('adcoset', '/admin/set_status', controller.admin.common.set_status);
  router.get('adcocap', '/admin/captcha', controller.admin.common.captcha);
  router.all('adcoup', '/admin/upload', controller.admin.common.upload);
  router.post('adcosvup', '/admin/save_upload', controller.admin.common.save_upload);
  router.redirect('/admin', '/admin/index/index');

  /*
  * socket.io
  * */
  io.of('/').route('server', io.controller.default.ping);
  
  app.all('/ueditor', ueditor(['app/public','public']),{
    "imageAllowFiles": [".png", ".jpg", ".jpeg"],
	  "imagePathFormat": "/upload/ueditor/image/{yyyy}{mm}{dd}/{filename}"
  });

};

